<html>
 <head>
  <script type="text/javascript" src="gwt-oauth2.js"></script>
 </head>
 <body>
   <!-- Demonstrates using the gwt-oauth2 library in a regular JS script. Note
   that the following files must be hosted in the same directory as this file:
   * gwt-oauth2.js, which is referenced in the script tag above. It can be
   moved/renamed.
   * oauthWindow.html, which is displayed breifly during the login process. -->
  <script type="text/javascript">
   ////////////////////////////////////////////////////////////////////////////
   // AUTHENTICATING WITH GOOGLE //////////////////////////////////////////////
   ////////////////////////////////////////////////////////////////////////////
   (function() {
     var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/auth";
     var GOOGLE_CLIENT_ID = "549650950581.apps.googleusercontent.com";
     var PLUS_ME_SCOPE = "https://www.googleapis.com/auth/plus.me";

     var button = document.createElement("button");
     button.innerText = "Authenticate with Google";
     button.onclick = function() {
       var req = {
         "authUrl" : GOOGLE_AUTH_URL,
         "clientId" : GOOGLE_CLIENT_ID,
         "scopes" : [ PLUS_ME_SCOPE ],
       };
       oauth2.login(req, function(token) {
         alert("Got an OAuth token:\n" + token + "\n"
             + "Token expires in " + oauth2.expiresIn(req) + " ms\n");
       }, function(error) {
         alert("Error:\n" + error);
       });
     };
     document.body.appendChild(button);

     var clearTokens = document.createElement("button");
     clearTokens.innerText = "Clear all tokens";
     clearTokens.onclick = oauth2.clearAllTokens;
     document.body.appendChild(clearTokens);
   })();
  </script>
 </body>
</html>
